﻿using System;
using System.Device.Location;
using System.Windows;
using MayhemCore;
using MayhemCore.ModuleTypes;

namespace MayhemWP7.Modules.Events.GeoLocation
{
    [MayhemModule("Radius Leave", "Triggers when you get a certain distance away from a point")]
    public class LeaveRadius : GeoLocationBase, IWp7Configurable
    {
        public LeaveRadius()
        {
        }

        protected override void CheckCoord(GeoCoordinate coord)
        {
            // If we are within the radius and we were previously outside of the radius
            if (coord.GetDistanceTo(Center) > Radius && (PrevLocation != null && PrevLocation.GetDistanceTo(Center) <= Radius)) {
                //if (coord.GetDistanceTo(Center) < Radius) {
                // then trigger
                base.OnEventActivated();
            }
        }

        #region Configuration Views

        public Uri Wp7Config()
        {
            return new Uri("/Modules/Pages/LeaveRadiusConfig.xaml", UriKind.RelativeOrAbsolute);
        }
        #endregion
    }
}
